package com.markus.code.exam.xiecheng;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/8 19:22
 * todo:
 */
public class PiMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            String str = scanner.nextLine();
            String[] nodes = str.split(" ");
            PiMain demo = new PiMain();
            demo.process(nodes,0,"");
        }
    }
    private void process(String[] nodes,int index,String path){
        if (index == nodes.length){
            if (isCircular(path)){
                System.out.println(path+"--circular dependency");
            }else{
                System.out.println(path);
            }
            return ;
        }
        char[] chars = nodes[index].toCharArray();
        for (int i=0;i<chars.length;i++){
            process(nodes,index+1,path+chars[i]);
        }
    }
    private boolean isCircular(String path){
        HashSet<Character> set = new HashSet<>();
        char[] chars = path.toCharArray();
        for (char aChar : chars) {
            if (set.contains(aChar)){
                return true;
            }else{
                set.add(aChar);
            }
        }
        return false;
    }
}
